import com.it.rabbitMQ.RabbitMQConsumerMainType;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

/**
 * projectName: spring_boot_RabbitQM
 *
 * @author: 王宝贵
 * time: 2024/9/12 11:03 周四
 * description:
 */
@SpringBootTest(classes = RabbitMQConsumerMainType.class)
public class deadQueue {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public static final String EXCHANGE_NORMAL = "exchange.normal.video";
    public static final String EXCHANGE_DEAD_LETTER = "exchange.dead.letter.video";

    public static final String ROUTING_KEY_NORMAL = "routing.key.normal.video";
    public static final String ROUTING_KEY_DEAD_LETTER = "routing.key.dead.letter.video";

    public static final String QUEUE_NORMAL = "queue.normal.video";
    public static final String QUEUE_DEAD_LETTER = "queue.dead.letter.video";


    /**
     * 死信测试1 消费者拒绝接受消息后会进入死信队列
     * 往正常队列里面发送消息 在消费者哪里消费的时候 拒绝接受 自动进行死信队列
     */
    @Test
    public void test(){
        rabbitTemplate
                .convertAndSend(
                        EXCHANGE_NORMAL,
                        ROUTING_KEY_NORMAL,
                        "测试死信情况1：消息被拒绝");
    }

    /**
     * 测试2 溢出 或许超时会进行死信队列里面
     * 正常队列最大容量是10 先存入20 会有10条溢出 到死信队列
     * 却 正常队列是设置了时间为10秒 10秒后正常队列里面的10条数据也会进入死信队里面
     */
    @Test
    public void testSendMultiMessage() {
        for (int i = 0; i < 20; i++) {
            rabbitTemplate.convertAndSend(
                    EXCHANGE_NORMAL,
                    ROUTING_KEY_NORMAL,
                    "测试死信情况2：消息数量超过队列的最大容量" + i);
        }
    }




}